

import BaseAd from "../../core/base/BaseAd";
import { registerClass } from "../../../cfw/tools/class_decorator";
import { NativeTemplateAd } from "../../native/native";
import { SDKLogicState, SDKState } from "../../SDKDefine";

// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html


@registerClass('MiMoCustomAd')
export default class MiMoCustomAd extends BaseAd {
    hide(): void {
        throw new Error("Method not implemented.");
    }

    protected ad: NativeTemplateAd;
    create() {
        let size = this.system.getVisibleSize();
        if (!this.ad) {
            this.ad = this.sdk.createTemplateAd({
                adUnitId: this.adUnitID,
                sizeIndex: 1,
                width: size.width,
                height: size.height
            })
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
        }

    }

    // open(func: ResultCallback) {
    //     this.resultCallback = func;
    //     this.destroy()
    //     this.create();
    //     this.load();
    // }

 
    load() {
        if (this.ad) {
            this.ad.load();
        }
    }

    show() {
        if (this.ad) {
            this.ad.show();
        }
    }

    destroy() {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.destroy();
            this.ad = null;
        }
    }
}
